package com.jiang.controller;

import com.jiang.dao.PersonMapper;
import com.jiang.entity.Person;
import com.jiang.utils.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/redis")
public class RedisController extends BaseController {
    @Autowired
    private PersonMapper personMapper;



    @RequestMapping("/ggg")
    public String showdd() {
        return "/ddd/redis";
    }

    @Cacheable(cacheNames = "cache0",key="#root.targetClass.simpleName+':'+#root.methodName+':'+#root.args")
    @RequestMapping("/select")
    @ResponseBody
    public Map<String, Object> select() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Person> list = personMapper.selectAll();
        map.put("list", list);
        return map;
    }

    @CacheEvict(cacheNames="cache0",allEntries = true)
    @RequestMapping("/del")
    @ResponseBody
    public String delById(int id){
        personMapper.deleteByPrimaryKey(id);
        return "删除成功";
    }

}
